package com.example.day01;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

public class Recy_Adapter extends RecyclerView.Adapter<Recy_Adapter.ViewHolder> {
        Context context;
        List<DataBean.ResultsBean> results;

    public Recy_Adapter(Context context, List<DataBean.ResultsBean> results) {
        this.context = context;
        this.results = results;
    }

    @NonNull
    @Override
    public Recy_Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.activity_recy, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Recy_Adapter.ViewHolder holder, int position) {

        Glide.with(context).load(results.get(position).getUrl()).into(holder.img1);


    }

    @Override
    public int getItemCount() {
        return results.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView img1;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img1=itemView.findViewById(R.id.img);
        }
    }
}
